<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>发布</title>
    <link rel="stylesheet" type="text/css" href="../style/api.css" />
    <link rel="stylesheet" type="text/css" href="../style/head.css" />
    <style>
        #closeIt {
            position: absolute;
            top: 35px;
            left: 1rem;
            width: 2rem;
            height: 2rem;
        }

        .history {
            position: absolute;
            top: 38px;
            right: 1rem;
        }

        main {
            padding-top: 75px;
        }

        .issueBox {
            margin: 1rem 0;
        }

        .issueItem {
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 95%;
            padding: 1.5rem;
            margin: auto;
            background-color: #fff;
            border-radius: 0.4rem;
            border-bottom: 2px solid #3949AB;
        }

        .issueItem span {
            font-size: 1rem;
        }

        .issueItem span:nth-child(1) {
            font-weight: bold;
            color: #3949AB;
        }

        .issueItem p {
            color: #999;
            margin: 0.5rem 0;
            line-height: 1.5;
        }

        .issueItem input {
            outline: none;
            width: 70%;
        }

        .toIssue {
            width: 95%;
            margin: 1rem auto;
            padding: 1rem;
            color: orange;
            text-align: center;
            border-radius: 0.4rem;
            background-color: #3949AB;
        }

        .theme {
            width: 95%;
            padding: 1.5rem;
            margin: auto;
            background-color: #fff;
            border-radius: 0.4rem;
            border-bottom: 2px solid #3949AB;
        }

        .theme span {
            font-weight: bold;
            color: #3949AB;
        }

        .theme textarea {
            resize: none;
            width: 100%;
            outline: none;
            margin: 0.5rem 0;
        }
    </style>
</head>

<body>
    <header>
        发布讲座
        <img src="../img/icons/back.png" alt="" onclick="api.closeWin()" id="closeIt">
        <span class="history">发布历史</span>
    </header>
    <main>
        <div class="issueBox">
            <div class="issueItem">
                <span>讲座名：</span>
                <input type="text" placeholder="请输入讲座名" id="name">
            </div>
            <div class="issueItem">
                <span>时间：</span>
                <input type="text" placeholder="请输入讲座时间" id="time">
            </div>
            <div class="issueItem">
                <span>地点：</span>
                <input type="text" placeholder="请输入讲座地点" id="place">
            </div>
            <div class="theme">
                <span>主题：</span>
                <textarea name="name" rows="8" cols="80" placeholder="输入讲座主题" id="theme"></textarea>
            </div>
            <div class="issueItem">
                <span>讲师：</span>
                <input type="text" placeholder="请输入讲师" id="teacher">
            </div>
            <div class="toIssue">发布</div>
        </div>
    </main>
</body>
<script type="text/javascript" src="../js/api.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
    apiready = function() {

    };

    $('.history').click(function() {
        api.openWin({
            name: 'history',
            url: './btb-history.html',
        });
    })

    $('.toIssue').click(function() {
        var name = $('#name').val();
        var time = $('#time').val();
        var place = $('#place').val();
        var theme = $('#theme').val();
        var teacher = $('#teacher').val();

        if(!name || $.trim(name).length == '0') {
            api.toast({
                msg: '讲座名称未输入',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        if(!time || $.trim(time).length == '0') {
            api.toast({
                msg: '讲座时间未输入',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        if(!place || $.trim(place).length == '0') {
            api.toast({
                msg: '讲座地点未输入',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        if(!theme || $.trim(theme).length == '0') {
            api.toast({
                msg: '讲座主题未输入',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        if(!teacher || $.trim(teacher).length == '0') {
            api.toast({
                msg: '讲座讲师未输入',
                duration: 2000,
                location: 'bottom'
            });
            return
        }
        api.ajax({
            url: 'http://114.116.243.15/newbtb/appinfo/addData.lecture',
            method: 'post',
            data: {
                body: {
                  'tbname': 'lecture_issue',
                  'issue_name': name,
                  'issue_time': time,
                  'issue_place': place,
                  'issue_theme': theme,
                  'issue_teacher': teacher,
                  'issue_uid': $api.getStorage('userid')
                }
            }
        },function(ret, err){
            if (ret) {
                if(ret.status == 1) {
                    api.toast({
                        msg: '发布成功，请等待审核',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });
    })
</script>

</html>
